﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;

namespace DAL
{
    public class UserDAL<T> :IUserDAL<T>    where T : class
    {
        public UserDAL(HotelDbContext db)
        {
            Db = db;
        }

        public HotelDbContext Db { get; }
        //添加
        public async Task<int> AddAsync(T t)
        {
            Db.Set<T>().AddAsync(t);
            return   await Db.SaveChangesAsync();   
        }
        //批量添加
        public async Task<int> AddAsyncd(List<T> t)
        {
            Db.Set<T>().AddRangeAsync(t);
            return await Db.SaveChangesAsync();
        }
        //删除
        public async Task<int> DeleteAsync(T t)
        {
            Db.Set<T>().Remove(t);
            return await Db.SaveChangesAsync();
        }
        ///批量删除
        public async Task<int> DeleteAsyncd(List<T> t)
        {
            Db.Set<T>().RemoveRange(t);
            return await Db.SaveChangesAsync();
        }

        public IQueryable<T> GetAllAsync()
        {
            
            return Db.Set<T>().AsQueryable();
        }
        //修改
        public async Task<int> UpdateAsync(T t)
        {
            Db.Set<T>().Update(t);
            return await Db.SaveChangesAsync();
        }
        //批量修改
        public async Task<int> UpdateAsyncd(List<T> t)
        {
            Db.Set<T>().UpdateRange(t);
            return await Db.SaveChangesAsync();
        }
    }
}
